# Maintainer: Maksim Bondarenkov <maksapple2306@gmail.com>

_realname=rust-analyzer
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
_pkgver=2025-05-19
pkgver=${_pkgver//-}
pkgrel=1
pkgdesc="A Rust compiler front-end for IDEs (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://rust-analyzer.github.io'
msys2_repository_url='https://github.com/rust-lang/rust-analyzer'
license=('spdx:Apache-2.0 OR MIT')
conflicts=("${MINGW_PACKAGE_PREFIX}-rust<1.80.0-2")
depends=("${MINGW_PACKAGE_PREFIX}-rust-src")
makedepends=('git')
source=("git+${msys2_repository_url}.git#tag=${_pkgver}")
sha256sums=('e547d7647b2805832165919c2c5c9e871947976ccae931dbef24ae1b855c14ce')

prepare() {
  cd "${_realname}"

  cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

build() {
  cd "${_realname}"

  export RUSTFLAGS="${RUSTFLAGS/+crt-static/-crt-static}"
  export CFG_RELEASE="${_pkgver} (Rev${pkgrel}, Built by MSYS2 project)"
  cargo build --frozen --release -p rust-analyzer
}

check() {
  cd "${_realname}"

  cargo test --frozen --release -p rust-analyzer
}

package() {
  cd "${_realname}"

  cargo install \
    --offline \
    --no-track \
    --frozen \
    --path crates/rust-analyzer \
    --root "${pkgdir}${MINGW_PREFIX}"

  install -Dm644 LICENSE-{APACHE,MIT} -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
}
